//
//  YFEmojiManager.swift
//  Emoji
//
//  Created by 余仿 on 16/4/18.
//  Copyright © 2016年 yf. All rights reserved.
//

import UIKit

class YFEmojiManager: NSObject {


    static let sharedEmojiManager:YFEmojiManager = YFEmojiManager()
    
    //用于存放每组对应的模型
    var packages:[YFPackage] = [YFPackage]()

    override init() {

        super.init()

        loadAllEmoji()
    }

    func loadAllEmoji(){

//        加载包含id的plist
        let path = NSBundle.mainBundle().pathForResource("emoticons.plist", ofType: nil, inDirectory: "Emoticons.bundle")!

        let dict = NSDictionary(contentsOfFile: path)!

        //取得包含id的数组
        let array = dict["packages"] as! [[String:AnyObject]]

        //获取id
        for value in array{

            let id = value["id"] as! String

            //根据id拼接绝对路径
            let filePath = "\(id)/info.plist"
            let absolutePath = NSBundle.mainBundle().pathForResource(filePath, ofType: nil, inDirectory: "Emoticons.bundle")!
            //根据绝对路径获取info.plist
//            根据路径加载字典
            let infoDict = NSDictionary(contentsOfFile: absolutePath)!

            //取两个键
//            group_name_cn String
//            emoticons Array

            let name = infoDict["group_name_cn"] as! String
            let emotions = infoDict["emoticons"] as! [[String:String]]

            let package = YFPackage(id: id, name: name, array: emotions)

            packages.append(package)

        }


    }
}
